{extend name="common/base" /}
{block name='title'}编辑参数 - 参数管理{/block}

{block name="body"}
<article class="clearfix pd-20">
    <form action="" method="post" class="form form-horizontal" id="form-set-edit">
        <input name="id" type="hidden" value="{$data.id}">
        <div class="row clearfix">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>参数名：</label>
            <div class="form-controls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="{$data.set_name}" placeholder="" id="set_name" name="set_name">
            </div>
        </div>
        <div class="row clearfix">
            <label class="form-label col-xs-4 col-sm-3">参数类型：</label>
            <div class="form-controls col-xs-8 col-sm-9"> <span class="select-box" style="width:150px;">
                <select class="select" name="type" size="1">
                    {foreach $types as $k=>$v}
                    <option {if $data.type == $k}selected{/if} value="{$k}">{$v}</option>
                    {/foreach}
                    
                </select>
                </span> </div>
        </div>
        <div class="row clearfix">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>关键字：</label>
            <div class="form-controls col-xs-8 col-sm-9">
                <input type="text" class="input-text" autocomplete="off" value="{$data.set_key}" placeholder="关键字" id="set_key" name="set_key">
            </div>
        </div>
        <div class="row clearfix" >
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>参数值：</label>
            {foreach $types as $k=>$v}
                {if $k == 1}
            <div class="form-controls col-xs-8 col-sm-9 set_type" id="type{$k}" {if $data.type != $k}style="display:none"{/if}>
                <input type="text" value="{$data.set_val}" class="input-text" autocomplete="off"  placeholder="参数值" id="set_val" name="set_val">
            </div>
                {elseif $k == 2}
            <div class="form-controls col-xs-8 col-sm-9 set_type" id="type{$k}" {if $data.type != $k}style="display:none"{/if}>
                <textarea name="set_val" cols="" rows="" class="textarea"  placeholder="说点什么...100个字符以内" dragonfly="true" onKeyUp="textarealength(this,100)">{$data.set_val}</textarea>
                <p class="textarea-numberbar"><em class="textarea-length">0</em>/100</p>
            </div>
                {elseif $k == 3}
            <div class="form-controls col-xs-8 col-sm-9 set_type" id="type{$k}"  {if $data.type != $k}style="display:none"{/if}>
                <script id="articleEditor" type="text/plain" style="width:100%;height:400px;">{$data.set_val|raw}</script>
            </div>
                {elseif $k == 4}
            <div class="form-controls col-xs-8 col-sm-9 set_type" id="type{$k}" {if $data.type != $k}style="display:none"{/if}>
                <div id="uploadLists" ><img src="{$data.set_val}" height="100"></div>

                <span class="btn-upload">
                    <a href="javascript:void();" class="btn btn-primary radius btn-upload"><i class="Hui-iconfont">&#xe642;</i> 浏览文件</a>
                    <input type="file"  name="btn-upload" id="btn-upload" class="input-file">

                </span>
            </div>
                {elseif $k == 5}
            <div class="form-controls col-xs-8 col-sm-9 set_type" id="type{$k}" {if $data.type != $k}style="display:none"{/if}>
                <?php $content = explode('|', $data['set_val']);?>
                <div id="uploadLists1" >
                    {foreach $content as $k1=>$v1}
                        <img src="{$v1}" height="100">
                    {/foreach}
                </div>
                <span class="btn-upload">
                    <a href="javascript:void();" class="btn btn-primary radius btn-upload"><i class="Hui-iconfont">&#xe642;</i> 浏览文件</a>
                    <input type="file" multiple name="btn-upload1" id="btn-upload1" class="input-file">
                </span>
            </div>
                {elseif $k == 6}
            <div class="form-controls col-xs-8 col-sm-9 set_type" id="type{$k}" {if $data.type != $k}style="display:none"{/if}>
                <span class="btn-upload">
                    <a href="javascript:void();" class="btn btn-primary radius btn-upload"><i class="Hui-iconfont">&#xe642;</i> 浏览文件</a>
                    <input type="file"  name="btnUploadFileThumb" id="btn-upload-file-thumb" class="input-file">
                </span>
            </div>
                {elseif $k == 7}
            <div class="form-controls col-xs-8 col-sm-9 set_type" id="type{$k}" {if $data.type != $k}style="display:none"{/if}>
                <span class="btn-upload">
                    <a href="javascript:void();" class="btn btn-primary radius btn-upload"><i class="Hui-iconfont">&#xe642;</i> 浏览文件</a>
                    <input type="file" multiple name="btnUploadFileThumb" id="btn-upload-file-thumb" class="input-file">
                </span>
            </div>
                {elseif $k == 8}
            <div class="form-controls col-xs-8 col-sm-9 set_type" id="type{$k}" {if $data.type != $k}style="display:none"{/if}>
                <span class="btn-upload">
                    <a href="javascript:void();" class="btn btn-primary radius btn-upload"><i class="Hui-iconfont">&#xe642;</i> 浏览文件</a>
                    <input type="file"  name="btnUploadFileThumb" id="btn-upload-file-thumb" class="input-file">
                </span>
            </div>
                {elseif $k == 9}
            <div class="form-controls col-xs-8 col-sm-9 set_type" id="type{$k}" {if $data.type != $k}style="display:none"{/if}>
                <span class="btn-upload">
                    <a href="javascript:void();" class="btn btn-primary radius btn-upload"><i class="Hui-iconfont">&#xe642;</i> 浏览文件</a>
                    <input type="file" multiple name="btnUploadFileThumb" id="btn-upload-file-thumb" class="input-file">
                </span>
            </div>
                {elseif $k == 10}
            <div class="form-controls col-xs-8 col-sm-9 skin-minimal set_type" id="type{$k}" {if $data.type != $k}style="display:none"{/if}>
                <div class="radio-box">
                    <input name="set_val" type="radio" value="1" {if $data.set_val == 1}checked{/if} id="sex-1" >
                    <label for="sex-1">本地</label>
                </div>
                <div class="radio-box">
                    <input type="radio" id="sex-2" value="2" {if $data.set_val == 2}checked{/if} name="set_val">
                    <label for="sex-2">百度云BOS</label>
                </div>
                <div class="radio-box">
                    <input type="radio" id="sex-3" value="3" {if $data.set_val == 3}checked{/if} name="set_val">
                    <label for="sex-3">阿里云OSS</label>
                </div>
                <div class="radio-box">
                    <input type="radio" id="sex-3" value="4" {if $data.set_val == 4}checked{/if} name="set_val">
                    <label for="sex-3">七牛云KODO</label>
                </div>
            </div>
               
          
                {/if}
            {/foreach}
            
        </div>
        

        
       
        <div class="row clearfix">
            <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                <input class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
            </div>
        </div>
    </form>
</article>
<input name="uploadImage" type="hidden" value="{:url('upload/uploadSet')}">
<input name="image" type="hidden" >
<input name="thumb" type="hidden" >
{/block}

{block name="js"}
<!--请在下方写此页面业务相关的脚本-->

<script type="text/javascript" src="__LIB__/jquery.validation/1.14.0/jquery.validate.js"></script>
<script type="text/javascript" src="__LIB__/jquery.validation/1.14.0/validate-methods.js"></script>
<script type="text/javascript" src="__LIB__/jquery.validation/1.14.0/messages_zh.js"></script>

<script type="text/javascript" src="__LIB__/webuploader/0.1.5/webuploader.min.js"></script>
<script type="text/javascript" src="__LIB__/ueditor/1.4.3/ueditor.config.js"></script>
<script type="text/javascript" src="__LIB__/ueditor/1.4.3/ueditor.all.min.js"> </script>
<script type="text/javascript" src="__LIB__/ueditor/1.4.3/lang/zh-cn/zh-cn.js"></script>
<script type="text/javascript" src="__JS__/main.js"></script>

<script type="text/javascript">
    $(function(){
        /* 通过iCheck插件，美化checkbox */
        $('.skin-minimal input').iCheck({
            checkboxClass: 'icheckbox-blue',
            radioClass: 'iradio-blue',
            increaseArea: '20%'
        });
        
        var ue = UE.getEditor('articleEditor');

        /* 表单验证，提交 */
        $("#form-set-edit").validate({
            rules:{
                id:{
                    required:true,
                },
                set_name:{
                    required:true,
                },
                type:{
                    required:true,
                },
                set_key:{
                    required:true,
                }
                
            },
            messages: {
              password2: {
                equalTo: "两次密码不一致",
              },
            },
            onkeyup:false,
            focusCleanup:true,
            success:"valid",
            submitHandler:function(form){
                
                var name = $("input[name='set_name']").val();
                var id = $("input[name='id']").val();
                var set_key = $("input[name='set_key']").val();
                var type = $("select[name='type']").val();
                var val = '';
                if(1 == type){
                    val = $("input[name='set_val']").val();
                }else if(2 == type){
                    val = $("textarea[name='set_val']").val();
                }else if(3 == type){
                    val = ue.getContent();;
                }else if(4 == type){
                    val = $("input[name='image']").val();
                }else if(5 == type){
                    val = $("input[name='image']").val();
                }else if(6 == type){
                    val = $("input[name='set_val']").val();
                }else if(8 == type){
                    val = $("input[name='set_val']").val();
                }else if(9 == type){
                    val = $("input[name='set_val']").val();
                }else if(10 == type){
                    val = $("input[name='set_val']:checked").val();
                }
                $.ajax({
                    type: 'post', // 提交方式 get/post
                    url: "{:url('set/edit')}", // 需要提交的 url
                    data: {
                        'name': name,
                        'set_key': set_key,
                        'set_val': val,
                        'type' : type,
                        'id' : id,
                        
                    },
                    dataType: 'json',
                    success: function(ret) { // data 保存提交后返回的数据，一般为 json 数据
                        // 此处可对 data 作相关处理
                        //console.log(ret);return false;
                        if(0 == ret.code){
                            layer.msg(ret.msg, { icon:1,time:1000 });
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.location.replace(parent.location.href)
                            parent.layer.close(index);
                        }else{
                            layer.msg(ret.msg, { icon:2,time:1000 });
                        }
                    }
                });
                
            }
        });
    });
    
    $("select[name='type']").bind('change',function(){
        var val = $(this).val();
        //console.log(val);return false;
        $(".set_type").hide();
        $("#type"+val).show();
    });
</script>
<!--/请在上方写此页面业务相关的脚本-->
{/block}
